/* 用户认证 */
import { wxLogin as wxLoginApi } from '../api/auth'
import apiCfg from '../config/api'

const accessTokenKey = apiCfg.accessTokenKey

/**
 * 微信第三方登录
 * 登录成功返回AccessToken对象
 *
 * @returns {AccessToken}
 */
export async function wxLogin() {
  const { code } = await wx.login()
  const { data } = await wxLoginApi({ code })
  await wx.setStorage({ key: accessTokenKey, data: data.access_token })
  return data.access_token
}
